// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf
        //static const MgcString& GetName () 
        //{ 
        //    return ms_kRTTI.GetName(); 
        //} 
#ifndef MGCRTTI_MCR
#define MGCRTTI_MCR

// insert in root class declaration
#define MgcDeclareRootRTTI \
    public: \
        static const MgcRTTI ms_kRTTI; \
        virtual const MgcRTTI* GetRTTI () const \
        { \
            return &ms_kRTTI; \
        } \
        bool IsExactlyClass (const MgcRTTI* pkQueryRTTI) const \
        { \
            return ( GetRTTI() == pkQueryRTTI ); \
        } \
        bool IsDerivedFromClass (const MgcRTTI* pkQueryRTTI) const \
        { \
            const MgcRTTI* pkRTTI = GetRTTI(); \
            while ( pkRTTI ) \
            { \
                if ( pkRTTI == pkQueryRTTI ) \
                    return true; \
                pkRTTI = pkRTTI->GetBaseRTTI(); \
            } \
            return false; \
        } \
        void* DynamicCast (const MgcRTTI* pkQueryRTTI) \
        { \
            return ( IsDerivedFromClass(pkQueryRTTI) ? this : 0 ); \
        }

// insert in derived class declaration
#define MgcDeclareRTTI \
    public: \
        static const MgcRTTI ms_kRTTI; \
        virtual const MgcRTTI* GetRTTI () const { return &ms_kRTTI; }

// insert in source file of root class of inheritance tree
#define MgcImplementRootRTTI(rootclassname) \
    const MgcRTTI rootclassname::ms_kRTTI(#rootclassname,0)

// insert in source file of derived class of inheritance tree
#define MgcImplementRTTI(classname,baseclassname) \
    const MgcRTTI classname::ms_kRTTI(#classname,&baseclassname::ms_kRTTI)

// runtime type testing and casting
#define MgcIsExactlyClass(classname,pObject) \
    ( pObject ? pObject->IsExactlyClass(&classname::ms_kRTTI) : false )

#define MgcIsDerivedFromClass(classname,pObject) \
    ( pObject ? pObject->IsDerivedFromClass(&classname::ms_kRTTI) : false )

#define MgcStaticCast(classname,pObject) \
    ((classname*)(void*)pObject)

#define MgcDynamicCast(classname,pObject) \
    ( pObject ? (classname*)pObject->DynamicCast(&classname::ms_kRTTI) : 0 )

#endif
